package com.atguigu.springcloud.alibaba.service.impl;

import com.atguigu.springcloud.alibaba.dao.TorderDao;
import com.atguigu.springcloud.alibaba.domain.Torder;
import com.atguigu.springcloud.alibaba.service.AccountService;
import com.atguigu.springcloud.alibaba.service.OrderService;
import com.atguigu.springcloud.alibaba.service.StorageService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * @Author: shikong
 * @Date: 2020/8/13 23:33
 */

@Service
@Slf4j
public class OrderServiceImpl implements OrderService {

    @Resource
    private TorderDao torderDao;

    @Resource
    private StorageService storageService;

    @Resource
    private AccountService accountService;


    @Override
    public void create(Torder order) {

        //1 新建订单
        log.info("----->创建订单开始");
        torderDao.create(order);
        log.info("----->创建订单结束");

        //扣减账户
        log.info("----->扣减账户开始");
        accountService.decrease(order.getUserId(),order.getMoney());
        log.info("----->扣减账户结束");

        //订单扣减
        log.info("----->扣减订单开始");
        storageService.storageUpdate(order.getProductId(),order.getCount());
        log.info("----->扣减订单开始");

        //4 修改订单状态，从零到1,1代表已经完成
        log.info("----->修改订单状态开始");
        torderDao.update(order.getUserId(),0);
        log.info("----->修改订单状态结束");
    }
}
